#include <stdio.h>

#define MAX_NODE 100
#define MAX_D    100000000

int M, N;

struct _Node
{
	int p;
	int l;
}Node[MAX_NODE];

int Engle[MAX_NODE][MAX_NODE] = {0};

struct _Table
{
	int k;
	int d;
	int l;
}Table[MAX_NODE];

void dijkstra(int s)
{
	int i, min_d, min_n;
	// init
	for (i = 0; i < N; ++i)
	{
		Table[i].k = 0;
		Table[i].d = MAX_D;
		Table[i].l = Node[i].l;
	}
	Table[s].d = 0;
	// dijkstra
	while (1)
	{	
		min_d = MAX_D;
		min_n = -1;
		// find min n;
		for (i = 0; i < N; i++)
		{
			if (!Table[i].k && Table[i].d < min_d)
			{
				min_d = Table[i].d;
				min_n = i;
			}
		}
		// break
		if (-1 == min_n)
			break;
		//
		for (i = 0; i < N; ++i)
		{
			if (   M >= Table[min_n].l - Node[i].l 
				&& !Table[i].k
				&& Engle[min_n][i]
				&& Table[i].d > Engle[min_n][i] + Table[min_n].d)
			{
				Table[i].d = Engle[min_n][i] + Table[min_n].d;
				Table[i].l = Node[i].l > Table[min_n].l ? Node[i].l : Table[min_n].l;
			}
		}
		//
		Table[min_n].k = 1;
	}		
}



void main()
{
	int P, L, X;
	int T, V;
	int i, n = 0;
	int r = MAX_D;

	scanf("%d %d", &M, &N);
	
	while (EOF != scanf("%d %d %d", &P, &L, &X))
	{
		Node[n].l = L;
		Node[n].p = P;
		for (i = 0; i < X; ++i)
		{
			scanf("%d %d", &T, &V);
			Engle[n][T - 1] = V;			
		}
		n++;
	}

	dijkstra(0);

	for (i = 0; i < N; ++i)
	{
		if (r > Table[i].d + Node[i].p)
		{
			r = Table[i].d + Node[i].p;
		}
	}
	printf("%d\n", r);		
}